package com.flower.enjoyment.flower.service.impl;

import com.flower.enjoyment.flower.entity.UserAppointment;
import com.flower.enjoyment.flower.entityDo.UserAppointmentDo;
import com.flower.enjoyment.flower.mapper.UserYuYueMapper;
import com.flower.enjoyment.flower.service.UserYuYueService;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
@Transactional(propagation = Propagation.SUPPORTS, readOnly = true, rollbackFor = Exception.class)
public class UserYuYueServiceImpl implements UserYuYueService {
    @Autowired
    private UserYuYueMapper userYuYueMapper;

    @Transactional
    @Override
    public int insert(UserAppointment record) {
        return userYuYueMapper.insert(record);
    }

    /**
     * 我的预约列表
     *
     * @param pageNo
     * @param pageSize
     * @param userId
     * @return
     */
    @Override
    public Page<UserAppointmentDo> selectUserYuYueListByPage(Integer pageNo, Integer pageSize, String userId) {
        PageHelper.startPage(pageNo, pageSize);
        return userYuYueMapper.selectUserYuYueListByPage(userId);
    }

    /**
     * 根据id获取预约详情
     *
     * @param id
     * @return
     */
    @Override
    public UserAppointmentDo getUserAppointmentById(String id) {
        return userYuYueMapper.selectByPrimaryKey(id);
    }

    /**
     * 更新预约信息
     *
     * @param userAppointment
     * @return
     */
    @Override
    public int updateUserAppointmentById(UserAppointment userAppointment) {
        return userYuYueMapper.updateByPrimaryKeySelective(userAppointment);
    }

    /**
     * 预约管理
     * 分页
     *
     * @param pageNo
     * @param pageSize
     * @param shopId
     * @return
     */
    @Override
    public Page<UserAppointmentDo> selectShopAppointmentListByPage(Integer pageNo, Integer pageSize, String shopId) {
        PageHelper.startPage(pageNo, pageSize);
        return userYuYueMapper.selectShopAppointmentListByPage(shopId);
    }

    /**
     * 预约管理
     * 不分页
     *
     * @param shopId
     * @return
     */
    @Override
    public List<UserAppointmentDo> selectShopAppointmentList(String shopId) {
        return userYuYueMapper.selectShopAppointmentList(shopId);
    }

    /**
     * 根据用户id获取用户店铺预约数量
     *
     * @param userId
     * @return
     */
    @Override
    public int selectCountByShopId(String userId) {
        return userYuYueMapper.selectCountByShopId(userId);
    }
}
